/*
 * Bubble sort is a straightforward and simplistic method of sorting data
 * that is used in computer science education.
 *
 * The algorithm starts at the beginning of the data set. 
 * It compares the first two elements, and if the first is greater than the 
 * second, it swaps them. It continues doing this for each pair of adjacent 
 * elements to the end of the data set. It then starts again with the first
 * two elements, repeating until no swaps have occurred on the last pass.
 * Although simple, this algorithm is highly inefficient and is rarely used 
 * except in education. A slightly better variant, cocktail sort, works by 
 * inverting the ordering criteria and the pass direction on alternating passes.
 *
 */

#include <iostream>
using namespace std;

void swap(int &a, int &b){
	int c=a;
	a=b;
	b=c;
}

int main(){
	int array[]={20,2,3,9,-2,50,10,5};
	int n=sizeof(array)/sizeof(int);
	for(int i=0;i<n;i++){
		for(int j=n-1;j>i;j--){
			if(array[j]<array[j-1]){
				swap(array[j],array[j-1]);
			}
		}
	}
	
	for(int i=0;i<n;i++){
		cout<<array[i]<<endl;
	}
}
